/**
 * 登陆界面
 * 
 * @author samsun
 * @version 1.0
 */
Ext.onReady(function() {

	Ext.QuickTips.init();
	// quer
	var loginForm = new Ext.FormPanel({
		// id:'form2',
		region : 'south',
		frame : true,
		height : 55,
		// autoHeight:true,
		labelAlign : 'right',
		labelPad : 0,
		layout : 'column',
		// autoHight:true,
		// bodyStyle:'padding:0px 0px 0',
		frame : 'false',
		border : 'false',
		items : [{
					columnWidth : .2,
					layout : 'form',
					frame : false,
					border : false,
					items : [{
								xtype : 'textfield',
								fieldLabel : '帐号',
								name : 'userName',
								cls : 'user',
								allowBlank : false
							}]
				}, {
					columnWidth : .2,
					layout : 'form',
					frame : false,
					border : false,
					items : [{
								cls : 'key',
								xtype : 'textfield',
								fieldLabel : '密码',
								name : 'password',
								inputType : 'password',
								allowBlank : false
							}]
				}, {}, {
					columnWidth : .1
				}, {
					columnWidth : .1,
					// bodyStyle:'padding:0px 10px 0',
					frame : false,
					border : false,
					items : [{
						xtype : 'button',
						type : 'submit',
						width : 80,
						name : 'login',
						text : '登录',
						handler : function() {
							// session.getAttribute("rand")
							if (loginForm.form.isValid()) {
								Ext.MessageBox.show({
											title : "请稍等",
											msg : "正在加载.....",
											progressText : "",
											width : 300,
											progress : true,
											closable : false,
											animEl : "loding"
										});
								var f = function(v) {
									return function() {
										var i = v / 11;
										Ext.MessageBox.updateProgress(i, '');
									}
								};
								for (var i = 1; i < 13; i++) {
									setTimeout(f(i), i * 150);
								}
								// 提交到服务器操作
								loginForm.form.doAction("submit", {
									url : "loginAction.action",
									method : "post",
									params : "",
									success : function(form, action) {	
										document.location =action.result.message;
									},
									failure : function(form, action) {
										if (action.result == undefined) {
											Ext.Msg
													.alert('提示',
															"系统出错...请联系管理员");
										} else {
											Ext.Msg.alert('提示',
													action.result.message);
										}
									}
								});
							}
						}
					}]

				}, {
					columnWidth : .1,
					bodyStyle : 'padding:0px 0px 0',
					frame : false,
					border : false,
					border : 0,
					items : [{
								xtype : 'button',
								width : 80,
								name : 'redo',
								text : '重置',
								handler : function() {
									loginForm.form.reset();
								}
							}]
				}, {
					columnWidth : .1,
					bodyStyle : 'padding:0px 0px 0',
					frame : false,
					border : false,
					border : 0,
					items : [{
						xtype : 'button',
						width : 80,
						name : 'register',
						text : '注册',
						handler : function() {
							
							registWindow.show();
						}
					}]
				}]
	});
	
	var headPanel = new Ext.Panel({
				bodyStyle : {
					"background-color" : "#0B0B61"
				},
				layout : 'border',
				id : 'head-panel',
				region : 'north', // this is what makes this panel into a
				// region within the containing layout
				width : '100%',
				height : 80,
				// autoHeight:true,
				border : false,
				items : [{
							xtype : 'panel',
							region : 'center',
							bodyStyle : {
								"padding" : "15px 0px 20px 0px",
								"background-color" : "#6699FF"
							},
							html : '<h1><font color="#FFFFF">WareHouse4WS</font><h1>'
						}, {
							region : 'west',
							html : '<img src="images/ist.bmp" width="80" height="80"/>'
						}]
			});
	var contentPanel = new Ext.Panel({
		bodyStyle : {
			"background-color" : "#A9D0F5"
		},
		id : 'content-panel',
		layout : 'border',
		region : 'center', // this is what makes this panel into a region
		// within the containing layout
		// width: '30%',
		border : false,
		// height: '50%',
		// autoHeight: true,
		// region:'border',
		items : [{
			region : 'center',
			// width:'100%',
			// autoWidth:false,
			// height:'100%',
			// autoHeight:true,
			html : '<p align=center><img src="images/businessmodeling.bmp" height="100%"/></p>'
		},
		loginForm
		]
	});
	// This is the Details panel that contains the description for each example
	// layout.
	var footPanel = new Ext.Panel({
				id : 'foot-panel',
				// layout:'border',
				region : 'south', // this is what makes this panel into a
				// region within the containing layout
				// width: '30%',
				height : 25,
				// autoHeight:true,
				border : false,
				bodyStyle : {
					"background-color" : "#6699FF"
				},
				html : '<p align=center><h2>all copyright reserved by sjtu.ist<h2></p>'
			});
	// Finally, build the main layout once all the pieces are ready. This is
	// also a good
	// example of putting together a full-screen BorderLayout within a Viewport.
	new Ext.Viewport({
				layout : 'border',
				title : 'WareHouse4WS',
				style : {
					"margin-left" : "100px", // when you add custom margin in
					// IE 6...
					"margin-right" : "100px" // Ext.isIE6 ? (Ext.isStrict ?
					// "-10px" : "-13px") : "-50px"
					// // you have to adjust for it
					// somewhere else
				},
				items : [headPanel, contentPanel, footPanel, {
							region : 'east',
							width : 0
						}, {
							region : 'west',
							width : 0
						}],
				renderTo : Ext.getBody()
			});

	
});
var registWindow=new Ext.Window({
								title : '注册信息',
								height : 260,
								width : 500,
								layout : 'fit',
								closeAction : 'hide',
								frame : 'true',
								plain : 'true',
								constrainHeader : 'true',
								resizable : false,
								modal : true,
								items : [editForm = new Ext.FormPanel({
									labelAlign : 'left',
									bodyStyle : 'padding:5px',
									buttonAlign : 'center',
									blankText : '不允许为空',
									labelSeparator : ":",
									labelWidth : 80,
									frame : true,
									items : [{
										layout : 'column',
										border : false,
										items : [{
													columnwidth : .5,
													layout : 'form',
													border : false,
													items : [{
																xtype : 'textfield',
																id:'userName',
																name : 'userName',
																fieldLabel : '用户姓名',
																maxlength : 20,
																maxLengthText:'长度不能超过20个字符',
																allowblank : false,
																blankText : "不能为空，请填写",
																maskRe : /[A-Za-z0-9]/,
																abchor : '90%'
															}]
												}, {
													columnwidth : 0.5,
													layout : 'form',
													border : false,
													items : [{
														xtype : 'panel',
														border : false,
														html : "<span style='color:red;'>*</span>"
													}]

												}]
									}, {
										layout : 'column',
										border : false,
										items : [{
													columnwidth : 0.5,
													layout : 'form',
													border : false,
													items : [{
																name : 'pw1',
																id:'password',
																xtype : 'textfield',
																inputType : 'password',
																fieldLabel : '密码',
																allowblank : false,
																maxlength : 20,
																maxLengthText:'长度不能超过20个字符',
																minlength: 6,
																minLengthText:'长度不能低于6个字符',
																blankText : "不能为空，请填写",
																abchor : '90%'
															}]
												}, {
													columnwidth : 0.5,
													layout : 'form',
													border : false,
													items : [{
														xtype : 'panel',
														border : false,
														html : "<span style='color:red;'>*</span>"
													}]

												}]
									}, {
										layout : 'column',
										border : false,
										items : [{
													columnwidth : 0.5,
													layout : 'form',
													border : false,
													items : [{
																name : 'pw2',
																xtype : 'textfield',
																inputType : 'password',
																fieldLabel : '确认密码',
																allowblank : false,
																maxlength : 20,
																maxLengthText:'长度不能超过20个字符',
																minlength: 6,
																minLengthText:'长度不能低于6个字符',
																blankText : "不能为空，请填写",
																abchor : '90%'
															}]
												}, {
													columnwidth : .5,
													layout : 'form',
													border : false,
													items : [{
														xtype : 'panel',
														border : false,
														html : "<span style='color:red;'>*</span>"
													}]

												}]
									}, {
										layout : 'column',
										border : false,
										items : [{
													columnwidth : .5,
													layout : 'form',
													border : false,
													items : [{
																id:'companyName',
																xtype : 'textfield',
																name : 'companyName',
																fieldLabel : '用户所在公司',
																allowblank : false,
																maxlength : 20,
																maxLengthText:'长度不能超过20个字符',
																blankText : "不能为空，请填写",
																abchor : '90%'
															}]
												}, {
													columnwidth : .5,
													layout : 'form',
													border : false,
													items : [{
														xtype : 'panel',
														border : false,
														html : "<span style='color:red;'>*</span>"
													}]

												}]
									}],
									buttons : [{
										text : '保存',
										scope : this,
										handler : function() {
											var obj = editForm;
											if (obj.form.isValid()) {
												var p1 = obj.form
														.findField('pw1');
												var p2 = obj.form
														.findField('pw2');
												if (p1.getValue() == p2
														.getValue()) {
													obj.form.submit(
															{
																url : "regist1.action",
																method : "post",
																params : "",
																success : function(form,response) {
																	var resjson=Ext.util.JSON.decode(response.response.responseText);
																	
																    Ext.Msg.alert("系统消息",resjson.message);
																    registWindow.hide();
																	obj.form.reset();
																},
																failure : function(form,response) {
																	Ext.Msg.alert("系统消息",response.response.responseText);
																	obj.form.reset();
																
																}
															})
												} else {
													Ext.Msg.alert('提示',"两次输入密码不一样");
												}
											}
										}
									}, {
										text : '重置',
										scope : this,
										handler : function() {
											editForm.form.reset();
										}
									}]
								})]

							});